<?php


abstract class BaseArticulo extends BaseObject  implements Persistent {


  const PEER = 'ArticuloPeer';

	
	protected static $peer;

	
	protected $id;

	
	protected $proveedor_id;

	
	protected $descuento_id;

	
	protected $categoria_id;

	
	protected $codigo;

	
	protected $nombre;

	
	protected $descripcion;

	
	protected $foto;

	
	protected $existencia;

	
	protected $costo;

	
	protected $precio;

	
	protected $color;

	
	protected $talla;

	
	protected $reorden;

	
	protected $tiempo_entrega;

	
	protected $fecha_compra;

	
	protected $aProveedor;

	
	protected $aDescuento;

	
	protected $aCategoria;

	
	protected $collArticuloVentas;

	
	private $lastArticuloVentaCriteria = null;

	
	protected $collSugerenciasRelatedByArticuloId;

	
	private $lastSugerenciaRelatedByArticuloIdCriteria = null;

	
	protected $collSugerenciasRelatedByRelacionado;

	
	private $lastSugerenciaRelatedByRelacionadoCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function __construct()
	{
		parent::__construct();
		$this->applyDefaultValues();
	}

	
	public function applyDefaultValues()
	{
		$this->foto = 'none.png';
		$this->existencia = 0;
	}

	
	public function getId()
	{
		return $this->id;
	}

	
	public function getProveedorId()
	{
		return $this->proveedor_id;
	}

	
	public function getDescuentoId()
	{
		return $this->descuento_id;
	}

	
	public function getCategoriaId()
	{
		return $this->categoria_id;
	}

	
	public function getCodigo()
	{
		return $this->codigo;
	}

	
	public function getNombre()
	{
		return $this->nombre;
	}

	
	public function getDescripcion()
	{
		return $this->descripcion;
	}

	
	public function getFoto()
	{
		return $this->foto;
	}

	
	public function getExistencia()
	{
		return $this->existencia;
	}

	
	public function getCosto()
	{
		return $this->costo;
	}

	
	public function getPrecio()
	{
		return $this->precio;
	}

	
	public function getColor()
	{
		return $this->color;
	}

	
	public function getTalla()
	{
		return $this->talla;
	}

	
	public function getReorden()
	{
		return $this->reorden;
	}

	
	public function getTiempoEntrega()
	{
		return $this->tiempo_entrega;
	}

	
	public function getFechaCompra($format = 'Y-m-d')
	{
		if ($this->fecha_compra === null) {
			return null;
		}


		if ($this->fecha_compra === '0000-00-00') {
									return null;
		} else {
			try {
				$dt = new DateTime($this->fecha_compra);
			} catch (Exception $x) {
				throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->fecha_compra, true), $x);
			}
		}

		if ($format === null) {
						return $dt;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $dt->format('U'));
		} else {
			return $dt->format($format);
		}
	}

	
	public function setId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = ArticuloPeer::ID;
		}

		return $this;
	} 
	
	public function setProveedorId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->proveedor_id !== $v) {
			$this->proveedor_id = $v;
			$this->modifiedColumns[] = ArticuloPeer::PROVEEDOR_ID;
		}

		if ($this->aProveedor !== null && $this->aProveedor->getId() !== $v) {
			$this->aProveedor = null;
		}

		return $this;
	} 
	
	public function setDescuentoId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->descuento_id !== $v) {
			$this->descuento_id = $v;
			$this->modifiedColumns[] = ArticuloPeer::DESCUENTO_ID;
		}

		if ($this->aDescuento !== null && $this->aDescuento->getId() !== $v) {
			$this->aDescuento = null;
		}

		return $this;
	} 
	
	public function setCategoriaId($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->categoria_id !== $v) {
			$this->categoria_id = $v;
			$this->modifiedColumns[] = ArticuloPeer::CATEGORIA_ID;
		}

		if ($this->aCategoria !== null && $this->aCategoria->getId() !== $v) {
			$this->aCategoria = null;
		}

		return $this;
	} 
	
	public function setCodigo($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->codigo !== $v) {
			$this->codigo = $v;
			$this->modifiedColumns[] = ArticuloPeer::CODIGO;
		}

		return $this;
	} 
	
	public function setNombre($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->nombre !== $v) {
			$this->nombre = $v;
			$this->modifiedColumns[] = ArticuloPeer::NOMBRE;
		}

		return $this;
	} 
	
	public function setDescripcion($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->descripcion !== $v) {
			$this->descripcion = $v;
			$this->modifiedColumns[] = ArticuloPeer::DESCRIPCION;
		}

		return $this;
	} 
	
	public function setFoto($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->foto !== $v || $v === 'none.png') {
			$this->foto = $v;
			$this->modifiedColumns[] = ArticuloPeer::FOTO;
		}

		return $this;
	} 
	
	public function setExistencia($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->existencia !== $v || $v === 0) {
			$this->existencia = $v;
			$this->modifiedColumns[] = ArticuloPeer::EXISTENCIA;
		}

		return $this;
	} 
	
	public function setCosto($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->costo !== $v) {
			$this->costo = $v;
			$this->modifiedColumns[] = ArticuloPeer::COSTO;
		}

		return $this;
	} 
	
	public function setPrecio($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->precio !== $v) {
			$this->precio = $v;
			$this->modifiedColumns[] = ArticuloPeer::PRECIO;
		}

		return $this;
	} 
	
	public function setColor($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->color !== $v) {
			$this->color = $v;
			$this->modifiedColumns[] = ArticuloPeer::COLOR;
		}

		return $this;
	} 
	
	public function setTalla($v)
	{
		if ($v !== null) {
			$v = (string) $v;
		}

		if ($this->talla !== $v) {
			$this->talla = $v;
			$this->modifiedColumns[] = ArticuloPeer::TALLA;
		}

		return $this;
	} 
	
	public function setReorden($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->reorden !== $v) {
			$this->reorden = $v;
			$this->modifiedColumns[] = ArticuloPeer::REORDEN;
		}

		return $this;
	} 
	
	public function setTiempoEntrega($v)
	{
		if ($v !== null) {
			$v = (int) $v;
		}

		if ($this->tiempo_entrega !== $v) {
			$this->tiempo_entrega = $v;
			$this->modifiedColumns[] = ArticuloPeer::TIEMPO_ENTREGA;
		}

		return $this;
	} 
	
	public function setFechaCompra($v)
	{
						if ($v === null || $v === '') {
			$dt = null;
		} elseif ($v instanceof DateTime) {
			$dt = $v;
		} else {
									try {
				if (is_numeric($v)) { 					$dt = new DateTime('@'.$v, new DateTimeZone('UTC'));
															$dt->setTimeZone(new DateTimeZone(date_default_timezone_get()));
				} else {
					$dt = new DateTime($v);
				}
			} catch (Exception $x) {
				throw new PropelException('Error parsing date/time value: ' . var_export($v, true), $x);
			}
		}

		if ( $this->fecha_compra !== null || $dt !== null ) {
			
			$currNorm = ($this->fecha_compra !== null && $tmpDt = new DateTime($this->fecha_compra)) ? $tmpDt->format('Y-m-d') : null;
			$newNorm = ($dt !== null) ? $dt->format('Y-m-d') : null;

			if ( ($currNorm !== $newNorm) 					)
			{
				$this->fecha_compra = ($dt ? $dt->format('Y-m-d') : null);
				$this->modifiedColumns[] = ArticuloPeer::FECHA_COMPRA;
			}
		} 
		return $this;
	} 
	
	public function hasOnlyDefaultValues()
	{
						if (array_diff($this->modifiedColumns, array(ArticuloPeer::FOTO,ArticuloPeer::EXISTENCIA))) {
				return false;
			}

			if ($this->foto !== 'none.png') {
				return false;
			}

			if ($this->existencia !== 0) {
				return false;
			}

				return true;
	} 
	
	public function hydrate($row, $startcol = 0, $rehydrate = false)
	{
		try {

			$this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null;
			$this->proveedor_id = ($row[$startcol + 1] !== null) ? (int) $row[$startcol + 1] : null;
			$this->descuento_id = ($row[$startcol + 2] !== null) ? (int) $row[$startcol + 2] : null;
			$this->categoria_id = ($row[$startcol + 3] !== null) ? (int) $row[$startcol + 3] : null;
			$this->codigo = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
			$this->nombre = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null;
			$this->descripcion = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null;
			$this->foto = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null;
			$this->existencia = ($row[$startcol + 8] !== null) ? (int) $row[$startcol + 8] : null;
			$this->costo = ($row[$startcol + 9] !== null) ? (string) $row[$startcol + 9] : null;
			$this->precio = ($row[$startcol + 10] !== null) ? (string) $row[$startcol + 10] : null;
			$this->color = ($row[$startcol + 11] !== null) ? (string) $row[$startcol + 11] : null;
			$this->talla = ($row[$startcol + 12] !== null) ? (string) $row[$startcol + 12] : null;
			$this->reorden = ($row[$startcol + 13] !== null) ? (int) $row[$startcol + 13] : null;
			$this->tiempo_entrega = ($row[$startcol + 14] !== null) ? (int) $row[$startcol + 14] : null;
			$this->fecha_compra = ($row[$startcol + 15] !== null) ? (string) $row[$startcol + 15] : null;
			$this->resetModified();

			$this->setNew(false);

			if ($rehydrate) {
				$this->ensureConsistency();
			}

						return $startcol + 16; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Articulo object", $e);
		}
	}

	
	public function ensureConsistency()
	{

		if ($this->aProveedor !== null && $this->proveedor_id !== $this->aProveedor->getId()) {
			$this->aProveedor = null;
		}
		if ($this->aDescuento !== null && $this->descuento_id !== $this->aDescuento->getId()) {
			$this->aDescuento = null;
		}
		if ($this->aCategoria !== null && $this->categoria_id !== $this->aCategoria->getId()) {
			$this->aCategoria = null;
		}
	} 
	
	public function reload($deep = false, PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("Cannot reload a deleted object.");
		}

		if ($this->isNew()) {
			throw new PropelException("Cannot reload an unsaved object.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ArticuloPeer::DATABASE_NAME, Propel::CONNECTION_READ);
		}

				
		$stmt = ArticuloPeer::doSelectStmt($this->buildPkeyCriteria(), $con);
		$row = $stmt->fetch(PDO::FETCH_NUM);
		$stmt->closeCursor();
		if (!$row) {
			throw new PropelException('Cannot find matching row in the database to reload object values.');
		}
		$this->hydrate($row, 0, true); 
		if ($deep) {  
			$this->aProveedor = null;
			$this->aDescuento = null;
			$this->aCategoria = null;
			$this->collArticuloVentas = null;
			$this->lastArticuloVentaCriteria = null;

			$this->collSugerenciasRelatedByArticuloId = null;
			$this->lastSugerenciaRelatedByArticuloIdCriteria = null;

			$this->collSugerenciasRelatedByRelacionado = null;
			$this->lastSugerenciaRelatedByRelacionadoCriteria = null;

		} 	}

	
	public function delete(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ArticuloPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			ArticuloPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	public function save(PropelPDO $con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(ArticuloPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
		}
		
		$con->beginTransaction();
		try {
			$affectedRows = $this->doSave($con);
			$con->commit();
			ArticuloPeer::addInstanceToPool($this);
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollBack();
			throw $e;
		}
	}

	
	protected function doSave(PropelPDO $con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;

												
			if ($this->aProveedor !== null) {
				if ($this->aProveedor->isModified() || $this->aProveedor->isNew()) {
					$affectedRows += $this->aProveedor->save($con);
				}
				$this->setProveedor($this->aProveedor);
			}

			if ($this->aDescuento !== null) {
				if ($this->aDescuento->isModified() || $this->aDescuento->isNew()) {
					$affectedRows += $this->aDescuento->save($con);
				}
				$this->setDescuento($this->aDescuento);
			}

			if ($this->aCategoria !== null) {
				if ($this->aCategoria->isModified() || $this->aCategoria->isNew()) {
					$affectedRows += $this->aCategoria->save($con);
				}
				$this->setCategoria($this->aCategoria);
			}

			if ($this->isNew() ) {
				$this->modifiedColumns[] = ArticuloPeer::ID;
			}

						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = ArticuloPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += ArticuloPeer::doUpdate($this, $con);
				}

				$this->resetModified(); 			}

			if ($this->collArticuloVentas !== null) {
				foreach ($this->collArticuloVentas as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collSugerenciasRelatedByArticuloId !== null) {
				foreach ($this->collSugerenciasRelatedByArticuloId as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collSugerenciasRelatedByRelacionado !== null) {
				foreach ($this->collSugerenciasRelatedByRelacionado as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;

		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aProveedor !== null) {
				if (!$this->aProveedor->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aProveedor->getValidationFailures());
				}
			}

			if ($this->aDescuento !== null) {
				if (!$this->aDescuento->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aDescuento->getValidationFailures());
				}
			}

			if ($this->aCategoria !== null) {
				if (!$this->aCategoria->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aCategoria->getValidationFailures());
				}
			}


			if (($retval = ArticuloPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collArticuloVentas !== null) {
					foreach ($this->collArticuloVentas as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collSugerenciasRelatedByArticuloId !== null) {
					foreach ($this->collSugerenciasRelatedByArticuloId as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collSugerenciasRelatedByRelacionado !== null) {
					foreach ($this->collSugerenciasRelatedByRelacionado as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ArticuloPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		$field = $this->getByPosition($pos);
		return $field;
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getProveedorId();
				break;
			case 2:
				return $this->getDescuentoId();
				break;
			case 3:
				return $this->getCategoriaId();
				break;
			case 4:
				return $this->getCodigo();
				break;
			case 5:
				return $this->getNombre();
				break;
			case 6:
				return $this->getDescripcion();
				break;
			case 7:
				return $this->getFoto();
				break;
			case 8:
				return $this->getExistencia();
				break;
			case 9:
				return $this->getCosto();
				break;
			case 10:
				return $this->getPrecio();
				break;
			case 11:
				return $this->getColor();
				break;
			case 12:
				return $this->getTalla();
				break;
			case 13:
				return $this->getReorden();
				break;
			case 14:
				return $this->getTiempoEntrega();
				break;
			case 15:
				return $this->getFechaCompra();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true)
	{
		$keys = ArticuloPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getProveedorId(),
			$keys[2] => $this->getDescuentoId(),
			$keys[3] => $this->getCategoriaId(),
			$keys[4] => $this->getCodigo(),
			$keys[5] => $this->getNombre(),
			$keys[6] => $this->getDescripcion(),
			$keys[7] => $this->getFoto(),
			$keys[8] => $this->getExistencia(),
			$keys[9] => $this->getCosto(),
			$keys[10] => $this->getPrecio(),
			$keys[11] => $this->getColor(),
			$keys[12] => $this->getTalla(),
			$keys[13] => $this->getReorden(),
			$keys[14] => $this->getTiempoEntrega(),
			$keys[15] => $this->getFechaCompra(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = ArticuloPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setProveedorId($value);
				break;
			case 2:
				$this->setDescuentoId($value);
				break;
			case 3:
				$this->setCategoriaId($value);
				break;
			case 4:
				$this->setCodigo($value);
				break;
			case 5:
				$this->setNombre($value);
				break;
			case 6:
				$this->setDescripcion($value);
				break;
			case 7:
				$this->setFoto($value);
				break;
			case 8:
				$this->setExistencia($value);
				break;
			case 9:
				$this->setCosto($value);
				break;
			case 10:
				$this->setPrecio($value);
				break;
			case 11:
				$this->setColor($value);
				break;
			case 12:
				$this->setTalla($value);
				break;
			case 13:
				$this->setReorden($value);
				break;
			case 14:
				$this->setTiempoEntrega($value);
				break;
			case 15:
				$this->setFechaCompra($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = ArticuloPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setProveedorId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setDescuentoId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCategoriaId($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCodigo($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setNombre($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setDescripcion($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setFoto($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setExistencia($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setCosto($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setPrecio($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setColor($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setTalla($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setReorden($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setTiempoEntrega($arr[$keys[14]]);
		if (array_key_exists($keys[15], $arr)) $this->setFechaCompra($arr[$keys[15]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);

		if ($this->isColumnModified(ArticuloPeer::ID)) $criteria->add(ArticuloPeer::ID, $this->id);
		if ($this->isColumnModified(ArticuloPeer::PROVEEDOR_ID)) $criteria->add(ArticuloPeer::PROVEEDOR_ID, $this->proveedor_id);
		if ($this->isColumnModified(ArticuloPeer::DESCUENTO_ID)) $criteria->add(ArticuloPeer::DESCUENTO_ID, $this->descuento_id);
		if ($this->isColumnModified(ArticuloPeer::CATEGORIA_ID)) $criteria->add(ArticuloPeer::CATEGORIA_ID, $this->categoria_id);
		if ($this->isColumnModified(ArticuloPeer::CODIGO)) $criteria->add(ArticuloPeer::CODIGO, $this->codigo);
		if ($this->isColumnModified(ArticuloPeer::NOMBRE)) $criteria->add(ArticuloPeer::NOMBRE, $this->nombre);
		if ($this->isColumnModified(ArticuloPeer::DESCRIPCION)) $criteria->add(ArticuloPeer::DESCRIPCION, $this->descripcion);
		if ($this->isColumnModified(ArticuloPeer::FOTO)) $criteria->add(ArticuloPeer::FOTO, $this->foto);
		if ($this->isColumnModified(ArticuloPeer::EXISTENCIA)) $criteria->add(ArticuloPeer::EXISTENCIA, $this->existencia);
		if ($this->isColumnModified(ArticuloPeer::COSTO)) $criteria->add(ArticuloPeer::COSTO, $this->costo);
		if ($this->isColumnModified(ArticuloPeer::PRECIO)) $criteria->add(ArticuloPeer::PRECIO, $this->precio);
		if ($this->isColumnModified(ArticuloPeer::COLOR)) $criteria->add(ArticuloPeer::COLOR, $this->color);
		if ($this->isColumnModified(ArticuloPeer::TALLA)) $criteria->add(ArticuloPeer::TALLA, $this->talla);
		if ($this->isColumnModified(ArticuloPeer::REORDEN)) $criteria->add(ArticuloPeer::REORDEN, $this->reorden);
		if ($this->isColumnModified(ArticuloPeer::TIEMPO_ENTREGA)) $criteria->add(ArticuloPeer::TIEMPO_ENTREGA, $this->tiempo_entrega);
		if ($this->isColumnModified(ArticuloPeer::FECHA_COMPRA)) $criteria->add(ArticuloPeer::FECHA_COMPRA, $this->fecha_compra);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);

		$criteria->add(ArticuloPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setProveedorId($this->proveedor_id);

		$copyObj->setDescuentoId($this->descuento_id);

		$copyObj->setCategoriaId($this->categoria_id);

		$copyObj->setCodigo($this->codigo);

		$copyObj->setNombre($this->nombre);

		$copyObj->setDescripcion($this->descripcion);

		$copyObj->setFoto($this->foto);

		$copyObj->setExistencia($this->existencia);

		$copyObj->setCosto($this->costo);

		$copyObj->setPrecio($this->precio);

		$copyObj->setColor($this->color);

		$copyObj->setTalla($this->talla);

		$copyObj->setReorden($this->reorden);

		$copyObj->setTiempoEntrega($this->tiempo_entrega);

		$copyObj->setFechaCompra($this->fecha_compra);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach ($this->getArticuloVentas() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addArticuloVenta($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getSugerenciasRelatedByArticuloId() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addSugerenciaRelatedByArticuloId($relObj->copy($deepCopy));
				}
			}

			foreach ($this->getSugerenciasRelatedByRelacionado() as $relObj) {
				if ($relObj !== $this) {  					$copyObj->addSugerenciaRelatedByRelacionado($relObj->copy($deepCopy));
				}
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new ArticuloPeer();
		}
		return self::$peer;
	}

	
	public function setProveedor(Proveedor $v = null)
	{
		if ($v === null) {
			$this->setProveedorId(NULL);
		} else {
			$this->setProveedorId($v->getId());
		}

		$this->aProveedor = $v;

						if ($v !== null) {
			$v->addArticulo($this);
		}

		return $this;
	}


	
	public function getProveedor(PropelPDO $con = null)
	{
		if ($this->aProveedor === null && ($this->proveedor_id !== null)) {
			$c = new Criteria(ProveedorPeer::DATABASE_NAME);
			$c->add(ProveedorPeer::ID, $this->proveedor_id);
			$this->aProveedor = ProveedorPeer::doSelectOne($c, $con);
			
		}
		return $this->aProveedor;
	}

	
	public function setDescuento(Descuento $v = null)
	{
		if ($v === null) {
			$this->setDescuentoId(NULL);
		} else {
			$this->setDescuentoId($v->getId());
		}

		$this->aDescuento = $v;

						if ($v !== null) {
			$v->addArticulo($this);
		}

		return $this;
	}


	
	public function getDescuento(PropelPDO $con = null)
	{
		if ($this->aDescuento === null && ($this->descuento_id !== null)) {
			$c = new Criteria(DescuentoPeer::DATABASE_NAME);
			$c->add(DescuentoPeer::ID, $this->descuento_id);
			$this->aDescuento = DescuentoPeer::doSelectOne($c, $con);
			
		}
		return $this->aDescuento;
	}

	
	public function setCategoria(Categoria $v = null)
	{
		if ($v === null) {
			$this->setCategoriaId(NULL);
		} else {
			$this->setCategoriaId($v->getId());
		}

		$this->aCategoria = $v;

						if ($v !== null) {
			$v->addArticulo($this);
		}

		return $this;
	}


	
	public function getCategoria(PropelPDO $con = null)
	{
		if ($this->aCategoria === null && ($this->categoria_id !== null)) {
			$c = new Criteria(CategoriaPeer::DATABASE_NAME);
			$c->add(CategoriaPeer::ID, $this->categoria_id);
			$this->aCategoria = CategoriaPeer::doSelectOne($c, $con);
			
		}
		return $this->aCategoria;
	}

	
	public function clearArticuloVentas()
	{
		$this->collArticuloVentas = null; 	}

	
	public function initArticuloVentas()
	{
		$this->collArticuloVentas = array();
	}

	
	public function getArticuloVentas($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collArticuloVentas === null) {
			if ($this->isNew()) {
			   $this->collArticuloVentas = array();
			} else {

				$criteria->add(ArticuloVentaPeer::ARTICULO_ID, $this->id);

				ArticuloVentaPeer::addSelectColumns($criteria);
				$this->collArticuloVentas = ArticuloVentaPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ArticuloVentaPeer::ARTICULO_ID, $this->id);

				ArticuloVentaPeer::addSelectColumns($criteria);
				if (!isset($this->lastArticuloVentaCriteria) || !$this->lastArticuloVentaCriteria->equals($criteria)) {
					$this->collArticuloVentas = ArticuloVentaPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastArticuloVentaCriteria = $criteria;
		return $this->collArticuloVentas;
	}

	
	public function countArticuloVentas(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collArticuloVentas === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(ArticuloVentaPeer::ARTICULO_ID, $this->id);

				$count = ArticuloVentaPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ArticuloVentaPeer::ARTICULO_ID, $this->id);

				if (!isset($this->lastArticuloVentaCriteria) || !$this->lastArticuloVentaCriteria->equals($criteria)) {
					$count = ArticuloVentaPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collArticuloVentas);
				}
			} else {
				$count = count($this->collArticuloVentas);
			}
		}
		$this->lastArticuloVentaCriteria = $criteria;
		return $count;
	}

	
	public function addArticuloVenta(ArticuloVenta $l)
	{
		if ($this->collArticuloVentas === null) {
			$this->initArticuloVentas();
		}
		if (!in_array($l, $this->collArticuloVentas, true)) { 			array_push($this->collArticuloVentas, $l);
			$l->setArticulo($this);
		}
	}


	
	public function getArticuloVentasJoinVenta($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collArticuloVentas === null) {
			if ($this->isNew()) {
				$this->collArticuloVentas = array();
			} else {

				$criteria->add(ArticuloVentaPeer::ARTICULO_ID, $this->id);

				$this->collArticuloVentas = ArticuloVentaPeer::doSelectJoinVenta($criteria, $con, $join_behavior);
			}
		} else {
									
			$criteria->add(ArticuloVentaPeer::ARTICULO_ID, $this->id);

			if (!isset($this->lastArticuloVentaCriteria) || !$this->lastArticuloVentaCriteria->equals($criteria)) {
				$this->collArticuloVentas = ArticuloVentaPeer::doSelectJoinVenta($criteria, $con, $join_behavior);
			}
		}
		$this->lastArticuloVentaCriteria = $criteria;

		return $this->collArticuloVentas;
	}

	
	public function clearSugerenciasRelatedByArticuloId()
	{
		$this->collSugerenciasRelatedByArticuloId = null; 	}

	
	public function initSugerenciasRelatedByArticuloId()
	{
		$this->collSugerenciasRelatedByArticuloId = array();
	}

	
	public function getSugerenciasRelatedByArticuloId($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collSugerenciasRelatedByArticuloId === null) {
			if ($this->isNew()) {
			   $this->collSugerenciasRelatedByArticuloId = array();
			} else {

				$criteria->add(SugerenciaPeer::ARTICULO_ID, $this->id);

				SugerenciaPeer::addSelectColumns($criteria);
				$this->collSugerenciasRelatedByArticuloId = SugerenciaPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(SugerenciaPeer::ARTICULO_ID, $this->id);

				SugerenciaPeer::addSelectColumns($criteria);
				if (!isset($this->lastSugerenciaRelatedByArticuloIdCriteria) || !$this->lastSugerenciaRelatedByArticuloIdCriteria->equals($criteria)) {
					$this->collSugerenciasRelatedByArticuloId = SugerenciaPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastSugerenciaRelatedByArticuloIdCriteria = $criteria;
		return $this->collSugerenciasRelatedByArticuloId;
	}

	
	public function countSugerenciasRelatedByArticuloId(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collSugerenciasRelatedByArticuloId === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(SugerenciaPeer::ARTICULO_ID, $this->id);

				$count = SugerenciaPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(SugerenciaPeer::ARTICULO_ID, $this->id);

				if (!isset($this->lastSugerenciaRelatedByArticuloIdCriteria) || !$this->lastSugerenciaRelatedByArticuloIdCriteria->equals($criteria)) {
					$count = SugerenciaPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collSugerenciasRelatedByArticuloId);
				}
			} else {
				$count = count($this->collSugerenciasRelatedByArticuloId);
			}
		}
		$this->lastSugerenciaRelatedByArticuloIdCriteria = $criteria;
		return $count;
	}

	
	public function addSugerenciaRelatedByArticuloId(Sugerencia $l)
	{
		if ($this->collSugerenciasRelatedByArticuloId === null) {
			$this->initSugerenciasRelatedByArticuloId();
		}
		if (!in_array($l, $this->collSugerenciasRelatedByArticuloId, true)) { 			array_push($this->collSugerenciasRelatedByArticuloId, $l);
			$l->setArticuloRelatedByArticuloId($this);
		}
	}

	
	public function clearSugerenciasRelatedByRelacionado()
	{
		$this->collSugerenciasRelatedByRelacionado = null; 	}

	
	public function initSugerenciasRelatedByRelacionado()
	{
		$this->collSugerenciasRelatedByRelacionado = array();
	}

	
	public function getSugerenciasRelatedByRelacionado($criteria = null, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collSugerenciasRelatedByRelacionado === null) {
			if ($this->isNew()) {
			   $this->collSugerenciasRelatedByRelacionado = array();
			} else {

				$criteria->add(SugerenciaPeer::RELACIONADO, $this->id);

				SugerenciaPeer::addSelectColumns($criteria);
				$this->collSugerenciasRelatedByRelacionado = SugerenciaPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(SugerenciaPeer::RELACIONADO, $this->id);

				SugerenciaPeer::addSelectColumns($criteria);
				if (!isset($this->lastSugerenciaRelatedByRelacionadoCriteria) || !$this->lastSugerenciaRelatedByRelacionadoCriteria->equals($criteria)) {
					$this->collSugerenciasRelatedByRelacionado = SugerenciaPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastSugerenciaRelatedByRelacionadoCriteria = $criteria;
		return $this->collSugerenciasRelatedByRelacionado;
	}

	
	public function countSugerenciasRelatedByRelacionado(Criteria $criteria = null, $distinct = false, PropelPDO $con = null)
	{
		if ($criteria === null) {
			$criteria = new Criteria(ArticuloPeer::DATABASE_NAME);
		} else {
			$criteria = clone $criteria;
		}

		if ($distinct) {
			$criteria->setDistinct();
		}

		$count = null;

		if ($this->collSugerenciasRelatedByRelacionado === null) {
			if ($this->isNew()) {
				$count = 0;
			} else {

				$criteria->add(SugerenciaPeer::RELACIONADO, $this->id);

				$count = SugerenciaPeer::doCount($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(SugerenciaPeer::RELACIONADO, $this->id);

				if (!isset($this->lastSugerenciaRelatedByRelacionadoCriteria) || !$this->lastSugerenciaRelatedByRelacionadoCriteria->equals($criteria)) {
					$count = SugerenciaPeer::doCount($criteria, $con);
				} else {
					$count = count($this->collSugerenciasRelatedByRelacionado);
				}
			} else {
				$count = count($this->collSugerenciasRelatedByRelacionado);
			}
		}
		$this->lastSugerenciaRelatedByRelacionadoCriteria = $criteria;
		return $count;
	}

	
	public function addSugerenciaRelatedByRelacionado(Sugerencia $l)
	{
		if ($this->collSugerenciasRelatedByRelacionado === null) {
			$this->initSugerenciasRelatedByRelacionado();
		}
		if (!in_array($l, $this->collSugerenciasRelatedByRelacionado, true)) { 			array_push($this->collSugerenciasRelatedByRelacionado, $l);
			$l->setArticuloRelatedByRelacionado($this);
		}
	}

	
	public function clearAllReferences($deep = false)
	{
		if ($deep) {
			if ($this->collArticuloVentas) {
				foreach ((array) $this->collArticuloVentas as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collSugerenciasRelatedByArticuloId) {
				foreach ((array) $this->collSugerenciasRelatedByArticuloId as $o) {
					$o->clearAllReferences($deep);
				}
			}
			if ($this->collSugerenciasRelatedByRelacionado) {
				foreach ((array) $this->collSugerenciasRelatedByRelacionado as $o) {
					$o->clearAllReferences($deep);
				}
			}
		} 
		$this->collArticuloVentas = null;
		$this->collSugerenciasRelatedByArticuloId = null;
		$this->collSugerenciasRelatedByRelacionado = null;
			$this->aProveedor = null;
			$this->aDescuento = null;
			$this->aCategoria = null;
	}

} 